

/*
* Copyright @ 2017 com.iflysse.trains
* crm 上午1:28:19
* All right reserved.
*
*/
	
package com.qf.dao.daoImpl;

import java.util.List;

import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.transaction.annotation.Transactional;

import com.qf.dao.CrmReferDao;
import com.qf.pojo.CrmFollow;
import com.qf.pojo.CrmRefer;
import com.qf.pojo.CrmStudent;

/**
* @desc: crm
* @descripe:XXXX
* @author: 周锐
* @createTime: 2017年7月27日 上午1:28:19
* @history:
* @version: v1.0

*/
@Transactional(value="txManager")
public class CrmReferDaoImpl implements CrmReferDao {
   private HibernateTemplate htl;
   
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmReferDao#addRefer(com.qf.pojo.CrmRefer)
	*/

	
/**
* @param htl the htl to set
*/

public void setHtl(HibernateTemplate htl) {

	this.htl = htl;
}

	@Override
	public void addRefer(CrmRefer refer) {

	    htl.save(refer);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmReferDao#updateRefer(com.qf.pojo.CrmRefer)
	*/

	@Override
	public void updateRefer(CrmRefer refer) {

		htl.update(refer);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmReferDao#findReferById(java.lang.Long)
	*/

	@Override
	public CrmRefer findReferById(Long referId) {

		//TODO
		return htl.get(CrmRefer.class, referId);

	}

	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmReferDao#finddReferByPage(int, int)
	*/

	@Override
	public List<CrmRefer> findReferByPage(int page, int size) {

		//TODO
		return htl.getSessionFactory().getCurrentSession().createQuery("from CrmRefer",CrmRefer.class).setFirstResult((page-1)*size).setMaxResults(size).getResultList();

	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmReferDao#findReferCount()
	*/
		
	@Override
	public int findReferCount() {
		
		//TODO
		return htl.getSessionFactory().getCurrentSession().createQuery("from CrmRefer",CrmRefer.class).getResultList().size();
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmReferDao#addFollow(com.qf.pojo.CrmFollow)
	*/
		
	@Override
	public void addFollow(CrmFollow follow) {
		
		htl.save(follow);
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmReferDao#findfollowbyrefer(java.lang.Long)
	*/
		
	@Override
	public List<CrmFollow> findfollowbyrefer(Long referId) {
		
		CrmRefer crmRefer = htl.get(CrmRefer.class, referId);
		return htl.getSessionFactory().getCurrentSession().createQuery("from CrmFollow as c where c.crmRefer=?",CrmFollow.class).setParameter(0, crmRefer).getResultList();
		
			
	}

	
	/*
	*(non-Javadoc)
	* @see com.qf.dao.CrmReferDao#addCrmStudent(com.qf.pojo.CrmStudent)
	*/
		
	@Override
	public void addCrmStudent(CrmStudent student) {
		
		htl.save(student);
			
	}

}

	